﻿// ATLSimpleObject2.cpp: CATLSimpleObject2 的实现

#include "pch.h"
#include "ATLSimpleObject2.h"
#include "D:\init\git_oschina\apps\system_info-master\StaticLib1\output.h"
//#include <Wbemidl.h>
// CATLSimpleObject2

static bool got = false;
static HardwareInfo info;

/*
*/
STDMETHODIMP CATLSimpleObject2::GetCpuType( BSTR *cpuType )
{
	// TODO: 在此处添加实现代码
	
	//GetHardwareInfo(&info);
	/*
	HRESULT hres;
	IWbemLocator* pLoc = NULL;
	hres = CoCreateInstance(
		CLSID_WbemLocator,
		0,
		CLSCTX_INPROC_SERVER,
		IID_IWbemLocator, (LPVOID*)& pLoc);
	*/
	if (!got) {
		GetHardwareInfoCompat(&info);
		got = true;
	}
	//BSTR  bs = SysAllocString(info.cpu);
	//memcpy(cpuType, bs, sizeof(bs));
	//pSvc->Release();
	//pLoc->Release();
	*cpuType = SysAllocString(info.cpu);	
	return S_OK;
}

/**
注册一个控件，然后实现功能
*/


STDMETHODIMP CATLSimpleObject2::test1(BSTR* outstr)
{
	// TODO: 在此处添加实现代码

	return S_OK;
}

/*
STDMETHODIMP CATLSimpleObject2::GetString(BSTR* str)
{
	*str = CComBSTR("Hello, String").Copy();

	return S_OK;
}
*/

/*
相关接口信息在如excel的vb环境中对象管理器是什么
*/
STDMETHODIMP CATLSimpleObject2::GetResult(BSTR* pVal)
{
	// TODO: 在此处添加实现代码
	*pVal = CComBSTR("Hello, String").Copy();
	return S_OK;
}


STDMETHODIMP CATLSimpleObject2::GetCpuId(BSTR*cpuId)
{
	// TODO: 在此处添加实现代码
	if (!got) {
		GetHardwareInfoCompat(&info);
		got = true;
	}
	*cpuId = SysAllocString(info.cpuId);
	return S_OK;
}


STDMETHODIMP CATLSimpleObject2::GetBiosType(BSTR* biosType)
{
	// TODO: 在此处添加实现代码
	if (!got) {
		GetHardwareInfoCompat(&info);
		got = true;
	}
	*biosType = SysAllocString(info.bios);
	return S_OK;
}


STDMETHODIMP CATLSimpleObject2::GetOsType(BSTR* osType)
{
	// TODO: 在此处添加实现代码
	if (!got) {
		GetHardwareInfoCompat(&info);
		got = true;
	}
	*osType = SysAllocString(info.os);
	return S_OK;
}


STDMETHODIMP CATLSimpleObject2::GetMotherBoardType(BSTR* motherboardtype)
{
	// TODO: 在此处添加实现代码
	if (!got) {
		GetHardwareInfoCompat(&info);
		got = true;
	}
	*motherboardtype = SysAllocString(info.mb);
	return S_OK;
}


STDMETHODIMP CATLSimpleObject2::GetMemoryInfo(BSTR* memoryinfo)
{
	// TODO: 在此处添加实现代码
	if (!got) {
		GetHardwareInfoCompat(&info);
		got = true;
	}
	*memoryinfo = SysAllocString(info.ram);
	return S_OK;
}


STDMETHODIMP CATLSimpleObject2::GetVideoInfo(BSTR* videoinfo)
{
	// TODO: 在此处添加实现代码
	if (!got) {
		GetHardwareInfoCompat(&info);
		got = true;
	}
	*videoinfo = SysAllocString(info.video);
	return S_OK;
}


STDMETHODIMP CATLSimpleObject2::GetDisplayInfo(BSTR* displayinfo)
{
	// TODO: 在此处添加实现代码
	if (!got) {
		GetHardwareInfoCompat(&info);
		got = true;
	}
	*displayinfo = SysAllocString(info.display);
	return S_OK;
}


STDMETHODIMP CATLSimpleObject2::GetStorageInfo(BSTR* storageinfo)
{
	// TODO: 在此处添加实现代码
	if (!got) {
		GetHardwareInfoCompat(&info);
		got = true;
	}
	*storageinfo = SysAllocString(info.storage);
	return S_OK;
}


STDMETHODIMP CATLSimpleObject2::GetCdRomInfo(BSTR* cdrominfo)
{
	// TODO: 在此处添加实现代码
	if (!got) {
		GetHardwareInfoCompat(&info);
		got = true;
	}
	*cdrominfo = SysAllocString(info.cdrom);
	return S_OK;
}


STDMETHODIMP CATLSimpleObject2::GetNetWorkInfo(BSTR* networkinfo)
{
	// TODO: 在此处添加实现代码
	if (!got) {
		GetHardwareInfoCompat(&info);
		got = true;
	}
	*networkinfo = SysAllocString(info.network);
	return S_OK;
}


STDMETHODIMP CATLSimpleObject2::GetAudioInfo(BSTR* audioinfo)
{
	// TODO: 在此处添加实现代码
	if (!got) {
		GetHardwareInfoCompat(&info);
		got = true;
	}
	*audioinfo = SysAllocString(info.audio);
	return S_OK;
}


STDMETHODIMP CATLSimpleObject2::GetHostName(BSTR* hostname)
{
	// TODO: 在此处添加实现代码
	if (!got) {
		GetHardwareInfoCompat(&info);
		got = true;
	}
	*hostname = SysAllocString(info.hostname);
	return S_OK;
}


STDMETHODIMP CATLSimpleObject2::get_MotherBoard(BSTR* pVal)
{
	// TODO: 在此处添加实现代码
	if (!got) {
		GetHardwareInfoCompat(&info);
		got = true;
	}
	*pVal = SysAllocString(info.mb);
	return S_OK;
}
